
//preloading.....
load("library/common.js");

JEuler.system.loadJS("library/math.js");

(function() {

    //JEuler.system.loadJS("data/???.dat");
    JEuler.system.printCaption("085");
    JEuler.system.startTimerCount();
    var N = 2000000;
    var x = Math.floor((Math.pow(N*4, 0.25)));
    
    var value, min=N;
    var i=0, j;
    do {
        i++;
        j = Math.sqrt(0.25+4*N/(i*(i+1))) - 0.5;
        j = Math.floor(j);
        value = (i)*(i+1)*(j)*(j+1)/4;
        if(Math.abs(value-N)<min) {
            JEuler.system.print(value + "..." + i + "x" + j + "=" + (i*j));
            min = Math.abs(value-N)
        }
        //print(value);
        j = j+1;
        value = (i)*(i+1)*(j)*(j+1)/4;
        if(Math.abs(value-N)<min) {
            JEuler.system.print(value + "..." + i + "x" + j + "=" + (i*j));
            min = Math.abs(value-N)
        }
        //print(value);
    } while(i<=j);
    
    //JEuler.system.print("SUM=" + sum);
    JEuler.system.printTimerCount();
    
})();
